home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigarom 1
/
Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso
/
FILES
/
DEV
/
I-Z
/
MacRecorder® HackersToolkit.cpt
/
SoundSample.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-11-21
|
3KB
|
126 lines
/* Copyright © 1989 Farallon Computing, Inc */
#include "Sound.h"
#include "DialogUtils.h"
#define NIL 0
/* dialog items */
enum
{
dDone = 1,
dRecord,
dPlay,
dModemPort,
dPrinterPort
};
main()
{
DialogPtr myDialog;
short itemHit = 0;
Handle theSound = 0;
short whichPort;
InitMac(); /* initialize managers */
/* no main event loop - just put up a modal dialog */
myDialog = GetNewDialog( 128, 0, -1);
/* do initialization for the dialog */
OutlineDefaultButton( myDialog);
whichPort = modemPort; /* default value */
SetRadioButton( myDialog, dModemPort); /* place bullet in radio button */
/* disable play until we get a sound to play */
UnHiliteDialogItem( myDialog, dPlay);
/* now ready to run the dialog */
while( itemHit != dDone)
{
ModalDialog( NIL, &itemHit);
switch( itemHit)
{
case dRecord:
/* first, dispose of previous sound, if any */
if (theSound != 0)
DisposHandle( theSound);
/*
** UnHiliteDialogItem buttons while recording
*/
UnHiliteDialogItem( myDialog, dRecord);
UnHiliteDialogItem( myDialog, dPlay);
/* get largest possible handle while leaving 2K around */
theSound = GetBigHandle( 2);
if (theSound == 0)
{
SysBeep(1); /* could not get the memory */
}
else
{
short result;
/*
** note:
** Record() will shrink the size of the
** Sound Handle down when it's done recording
** if the full amount of available memory in
** the Handle is not used when recording
*/
result = Record( theSound, whichPort);
if (result == recordErr)
{
/* recording error */
SysBeep(1);
DisposHandle( theSound);
theSound = 0;
}
else
{
/* play ok now */
HiliteDialogItem( myDialog, dPlay);
}
}
/* record ok now */
HiliteDialogItem( myDialog, dRecord);
break;
case dPlay:
/* UnHiliteDialogItem buttons while playing */
UnHiliteDialogItem( myDialog, dRecord);
UnHiliteDialogItem( myDialog, dPlay);
/* use toolbox's Sound Manager to play the sound */
SndPlay( NIL, theSound, false);
/* Ok to Record / Play again */
HiliteDialogItem( myDialog, dRecord);
HiliteDialogItem( myDialog, dPlay);
break;
case dModemPort:
ToggleRadioButtons( myDialog, dPrinterPort, dModemPort);
whichPort = modemPort;
break;
case dPrinterPort:
ToggleRadioButtons( myDialog, dModemPort, dPrinterPort);
whichPort = printerPort;
break;
}
}
/* clean-up */
DisposDialog( myDialog);
/* dispose of sound, if any */
if (theSound != 0)
DisposHandle( theSound);
}